<template>
		<button class="auth"  open-type="getUserInfo" @getuserinfo="getuserinfo" :disabled="infoList.disabled" >
			点击登录并授权
		</button>
</template>

<script>
	import api from '@/pages/utils/api.js';
	export default{
		data() {
			return {
				
			}
		},
		onLoad() {
		
		},
		methods: {
			getuserinfo(res){//调起微信登录授权
			var vm = this;
				wx.getSetting({
					   success: function (res) {
							if (res.authSetting['scope.userInfo']) 
							{
							 wx.getUserInfo({
								  success: function (res) {
									//记录用户身份
									api.getMember({}).then(info=>{
										if(info.code == 1){ 
											uni.setStorageSync('identity',info.data.type);//身份信息（企业 || 用户）
											uni.setStorageSync('isreseller',info.data.isreseller)//身份信息（分销商 || 非分销商）
										}
									});
									//获取用户信息（判断上级）	
									api.getUserInfo({
										encryptedData:res.encryptedData,
										iv:res.iv,
										sessionKey:uni.getStorageSync('session_key'),
										agentid:uni.getStorageSync('agentid') || '',
									}).then(info=>{
										if(info.code == 1){ 
											 
										}
									});
									uni.navigateBack({
									    delta: 1
									});
								  }
							 });
							} 
					   }
				  })
			},
		}
	}
</script>

<style>
	.auth{
		background: #F7AE2B;
		color:#FFF;
		border-radius: 10upx;
		width: 70%;
		margin:50% auto;
		text-align: center;
	}
</style>
